var borAuditOption = {
    //重新填写资料
    modifyApply : function(borId,taskId,data,pointUserStatus,pointUser){
        $("#borDeptTwo").empty();
        //获取驳回资料
        var AppliInfo = '';
        $.ajax({
            url:BASE_PATH + "/pcwindow/getModifyAppliInfo",
            data:{borId:borId},
            type:"post",
            async:false,
            success:function(result){
                AppliInfo = result;
            }
        });
        var borDeptId = data.borDeptId;
        var taskType = data.taskType;
        if(taskType==1){
            $("#applyTableType").val("renewTable");
            $("#renewPurpose").val(data.renewPurpose)
            $("#renewTime").val(formatshortDateTime(data.renewReturnTime))
            $("#rejectReason").text(AppliInfo.extend1+" : "+AppliInfo.auditUserView);
        }else{
            if(borDeptId==null||borDeptId==""){
                //无组织，无纪律的
                $("#applyTableType").val("borrowNoDeptTable");
                $("#borDept").val(data.borDeptDescription);
                // $("#borNoDeptTime").val(formatshortDateTime(data.borTime));
                $("#returnNoDeptTime").val(formatshortDateTime(data.planReturnTime));
                $("#borType").val(data.borType).select2();
                $("#borNoDeptPurpose").val(data.borPurpose);
                $("#rejectReason").text(AppliInfo.extend1+" : "+AppliInfo.auditUserView);
            }else{
                $("#borDeptTwo").val(data.borDeptName);
                $("#borDeptTwo").attr("borDeptId",data.borDeptId);
                // $("#bortimeTwo").val(formatshortDateTime(data.borTime));
                $("#planReturnTimeTwo").val(formatshortDateTime(data.planReturnTime));
                $("#borTypeTwo").val(data.borType).select2();
                $("#borPurposeTwo").val(data.borPurpose);
                $("#rejectReason").text(AppliInfo.extend1+" : "+AppliInfo.auditUserView);
                //有组织，有纪律的
                $("#applyTableType").val("borrowDeptTable");
            }
        }
        if(pointUserStatus){
            $.ajax({
                url:BASE_PATH+"/pcwindow/showAllUser",
                type:'get',
                data:"",
                dataType:"json",
                success:function (data) {
                    $('#modifyUserTable').empty();
                    $('#modifyUserTable').select2({
                        placeholder: '请选择下一个审批人',
                        allowClear: true
                    });
                    var allList = data.rows;
                    var option = '';
                    for(var index in allList){
                        var user = allList[index];
                        option += "<option value='"+user.firstName+"'>"+user.lastName+"</option>";
                    }
                    var $option = $(option);
                    $("#modifyUserTable").append($option);
                }
            })
            $("#modifyUserTable").attr("data-delegateUser",pointUser);
            $("#modifyPointUserDiv").show();
        }else{
            $("#modifyPointUserDiv").hide();
            $("#modifyUserTable").attr("data-delegateUser",'');
        }
        $("#borModifyId").val(borId);
        $("#taskModifyId").val(taskId);
        $("#modifyTaskType").val(data.taskType);
        $("#modifyApply").modal("show");
    },
    //流程办理
    processHandle:function(borId,taskId,data,taskName,pointUserStatus,pointUser){
        $("#filesTitle").text("流程办理["+taskName+"]");
        $("#taskType").val(data.taskType);
        if(data.taskType==0){
            $("#borTaskType").text("借阅");
            $("#createTime").text(formatDateTime(data.createTime));
            $("#planReturnTime").text(formatshortDateTime(data.planReturnTime));
            $("#borPurpose").text(data.borPurpose);
        }else if(data.taskType==1){
            $("#borTaskType").text("续借");
            $("#createTime").text(formatDateTime(data.updateTime));
            $("#planReturnTime").text(formatshortDateTime(data.renewReturnTime));
            $("#borPurpose").text(data.renewPurpose);
        }
        if(data.borType==0){
            $("#borrowType").text("线上");
        }else{
            $("#borrowType").text("线下");
        }
        $("#borUserName").text(data.borUserName);
        if(data.borDeptName!=null){
            $("#borDeptName").text(data.borDeptName);
        }else{
            $("#borDeptName").text(data.borDeptDescription);
        }
        //如果没有组织部门id，则显示查看证明的字段
        if(data.borDeptId){
            $("#borAttestUrlTr").hide();
            $("#urlHidden").val("");
        }else{
            $("#urlHidden").val(data.borAttestUrl);
            $("#borAttestUrlTr").show();
        }
        // $("#borFileName").text(data.borFileName);
        $("#borId").val(borId);
        $("#taskId").val(taskId);
        if(pointUserStatus){
            $.ajax({
                url:BASE_PATH+"/pcwindow/showAllUser",
                type:'get',
                data:"",
                dataType:"json",
                success:function (data) {
                    $('#auditUserTable').empty();
                    $('#auditUserTable').select2({
                        placeholder: '请选择下一个审批人',
                        allowClear: true
                    });
                    var allList = data.rows;
                    var option = '';
                    for(var index in allList){
                        var user = allList[index];
                        option += "<option value='"+user.firstName+"'>"+user.lastName+"</option>";
                    }
                    var $option = $(option);
                    $("#auditUserTable").append($option);
                }
            })
            $("#auditUserTable").attr("data-delegateUser",pointUser);
            $("#auditPointUserDiv").show();
        }else{
            $("#auditPointUserDiv").hide();
            $("#auditUserTable").attr("data-delegateUser",'');
        }
        $("#borAuditInfo").modal("show");
    },

    //确认提交按钮
    borAuditFinishResult:function (evn){
        $(evn).attr("disable",true);
        var $evn = $(evn);
        var borModifyId = $("#borModifyId").val();
        var taskModifyId = $("#taskModifyId").val();
        var isApply = $('#modifyApply').find(":checked").val();
        var taskType = $("#modifyTaskType").val();
        //获取当前要显示的申请table
        var applyTableType = $("#applyTableType").val();
        var flag = '';
        if(isApply==0){
            flag = false;
            $.ajax({
                url:BASE_PATH + "/pcwindow/borAuditResult",
                type:"post",
                data:{taskId:taskModifyId,borId:borModifyId,auditUserView:"取消申请",keys:"reApply",values:flag,types:'B',taskType:taskType},
                dataType:"json",
                success:function(data){
                    if(data.code==1){
                        $("#modifyApply").modal("hide");
                        $borAuditTable.bootstrapTable('refresh');
                    }
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    confirmEvent('系统开小差了，请稍后再试!');
                }
            })
        }else{
            var delegateUser;
            var userName;
            var flag = true;
            var formData = new FormData();
            var returnTime = '';
            formData.append("taskId",taskModifyId);
            formData.append("borId",borModifyId);
            formData.append("keys","reApply");
            formData.append("values",flag);
            formData.append("types","B");
            //如果当前页面为无组织机构的用户
            if(applyTableType=="borrowNoDeptTable"){
                if(!modifyValidator(0)){
                    $evn.attr("disable",false);
                    return ;
                }
                var file=$("#borrowNoDeptfile")[0].files[0];
                formData.append("file",file);
                formData.append("borDeptDescription",$("#borDept").val());
                formData.append("borType",$("#borType").find(":selected").val());
                // formData.append("borTime",$("#borNoDeptTime").val());
                formData.append("planReturnTime",$("#returnNoDeptTime").val());
                formData.append("borPurpose",$("#borNoDeptPurpose").val());
                formData.append("taskType",taskType);
                returnTime = $("#returnNoDeptTime").val();
            }else if(applyTableType=="borrowDeptTable"){
                if(!modifyValidator(1)){
                    $evn.attr("disable",false);
                    return ;
                }
                formData.append("borDeptId",$("#borDeptTwo").attr("borDeptId"));
                formData.append("borType",$("#borTypeTwo").find(":selected").val());
                // formData.append("borTime",$("#bortimeTwo").val());
                formData.append("planReturnTime",$("#planReturnTimeTwo").val());
                formData.append("borPurpose", $("#borPurposeTwo").val());
                formData.append("taskType",taskType);
                returnTime = $("#planReturnTimeTwo").val();
            }else{
                formData.append( "renewPurpose",$("#renewPurpose").val());
                formData.append( "renewReturnTime",$("#renewTime").val());
                formData.append("taskType",taskType);
                returnTime = $("#renewTime").val();
            }
            //替代实际人
            delegateUser=$("#modifyUserTable").attr("data-delegateUser");

            //判断当前是否为指定审批人表达式
            if(delegateUser!=''||typeof(delegateUser)!="undefined"){
                userName=$("#modifyUserTable").val();
            }
            formData.append("delegateUser",delegateUser);
            formData.append("userName",userName);
            var returnData = strToDate(returnTime);
            var nowDate = new Date();
            if(nowDate>returnData){
                confirmEvent('时间不可小于或等于当前时间');
                $(evn).attr("disabled",false);
                return;
            }
            $.ajax({
                url:BASE_PATH + "/pcwindow/modifyBorAudit",
                method:"post",
                data: formData ,
                processData: false,
                contentType: false,
                success:function(data){
                    if(data.code==1){
                        $("#modifyApply").modal("hide");
                        $evn.attr("disable",false);
                        $borAuditTable.bootstrapTable('refresh');
                    }
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    confirmEvent('系统开小差了，请稍后再试!');
                    $evn.attr("disable",false);
                }
            })
        }
    }
}

//修改表单验证
function modifyValidator(type){
    var flag = true;
    //没有组织部门
    var borDept;
    // var borTime;
    var planReturnTime;
    var borPurpose;
    var str = "";
    if(type==0){
        borDept = $("#borDept").val();
        // borTime = $("#borNoDeptTime").val();
        planReturnTime = $("#returnNoDeptTime").val();
        borPurpose = $("#borNoDeptPurpose").val();
        //如果有组织机构
    }else{
        borDept = $("#borDeptTwo").attr("borDeptId");
        planReturnTime = $("#planReturnTimeTwo").val();
        borPurpose = $("#borPurposeTwo").val();
    }
    if(borDept==null||borDept==""){
        flag = false;
        str += "组织部门 ";
    }
    if(planReturnTime==null||planReturnTime==""){
        flag = false;
        str += "归还时间 ";
    }
    if(borPurpose==null||borPurpose==""){
        flag = false;
        str += "借阅理由 ";
    }
    if(!flag){
        confirmEvent(str + "不能为空");
    }
    return flag;
}